package com.catsic.security.x509;

import java.security.Principal;
import java.security.cert.X509Certificate;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;

public class SecurityX509PrincipalExtractor implements X509PrincipalExtractor{

	/** 
     * 获取证书序列号 
     * @param cert x509证书对象 
     */ 
	@Override
	public String extractPrincipal(X509Certificate cert) {
		//String serialNumber = cert.getSerialNumber().toString(16);  
        Principal pSubject = cert.getSubjectDN(); 
        String certSubject = pSubject.getName();
		if(StringUtils.isNotBlank(certSubject)){
         	 String[] ss=certSubject.split(",");
         	 String[] user = ss[0].split("=");
         	 return user[1];
        }
		return null;
	}

}
